package com.example.testblog.web.admin;

import com.example.testblog.entity.BlogQuery;
import com.example.testblog.service.BlogService;
import com.example.testblog.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;



@Controller
@RequestMapping(value = "/admin")
public class BlogController {


    @Autowired
    private BlogService blogService;

    @Autowired
    private TypeService typeService;

    @RequestMapping(value = "/blog_input")
    public  String blog_input( )
    {

        return "/admin/blog_input";
    }


    @GetMapping("blog")
    public  String blog(@PageableDefault(size = 3,sort = {"updateTime"},direction = Sort.Direction.DESC)Pageable pageable, BlogQuery blogQuery, Model model)
    {
        model.addAttribute("type", typeService.listType());
        model.addAttribute("page", blogService.ListBlog(pageable, blogQuery));
        return "/admin/blog";
    }
}
